package cn.ejiajunxy.manager.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.leo.baseui.tabview.TabsView;

import java.util.ArrayList;
import java.util.List;

import cn.ejiajunxy.manager.R;

/**
 * Created by zhangguobao on 2018/3/11.
 */

public class FragmentOrder extends Fragment {
    private TabsView clTabs;
    private ViewPager vpContent;
    MainFragmentAdapter mAdapter;
    private List<String> mTitle;
    private View mView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mView == null) {
            mView = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_order, container, false);
            initViews();
        }
        return mView;
    }

    private void initViews() {
        mTitle = new ArrayList<>();
        mTitle.add("未送订单");
        mTitle.add("已送订单");
        clTabs = (TabsView) mView.findViewById(R.id.clTabs);
        vpContent = (ViewPager) mView.findViewById(R.id.vpContent);
        mAdapter = new MainFragmentAdapter(getChildFragmentManager());
        vpContent.setAdapter(mAdapter);
        vpContent.setCurrentItem(0);
        clTabs.notifyDataChanged(mTitle, 0);
        clTabs.setupWithViewPager(vpContent);
        clTabs.setOnItemSelectListener(new TabsView.OnItemSelectListener() {
            @Override
            public void onSelect(int position, String title) {
                vpContent.setCurrentItem(position);
            }
        });
    }

    private class MainFragmentAdapter extends FragmentPagerAdapter {
        public MainFragmentAdapter(FragmentManager fm) {
            super(fm);
        }


        @Override
        public Fragment getItem(int position) {
            return FragmentOrderList.newInstance(position);
        }

        @Override
        public int getCount() {
            return 2;
        }
    }
}
